<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ include file="/WEB-INF/jsp/common/common.jsp"%>
<script src="${path}/apps_res/cip/common/js/cip.js${ctp:resSuffix()}"></script>
<%@ include file="/WEB-INF/jsp/cip/seeyonconfig/startParamAuthInclud.jsp"%>
<title>业务流程集成</title>
</head>
<% boolean hasPlugin = com.seeyon.apps.cip.business.manager.BusinessFlowAuthFactory.getInstance().hasPlugin(); %>
<c:set var="hasBusinessPlugin" value="<%=hasPlugin%>"/>
<body>
<script type="text/javascript">
var treeObj;
var inputId;
var nodeChildrenIds = "-1";
//前端缓存，key-formId,value-processId
var businessMap = new Properties();
var windowsMap;
$(document).ready(function() {

    initTree();
    initToolbar();
    if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&!isAccountCtlForBusienss}"==="false"){
    initGrid();
    }
    //集团管控-单位管理员 进行提示
    if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&!isAccountCtlForBusienss}"==="true"){
      $.alert("${ctp:i18n('cip.business.auth.tip')}");
    }else{
      initSearchObj();
    }
});

function updateBusiness(){
  //单位管控-集团管理员 进行提示，不允许修改
  if("${v3x:currentUser().isGroupAdmin()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"==="true"){
      $.alert("${ctp:i18n('cip.business.updateByUnitAdmin')}");
      return;
  }
  var v = $("#businessTable").formobj({
      gridFilter : function(data, row) {
          return $("input:checkbox", row)[0].checked;
      }
  });
  if (v.length < 1||v.length > 1) {
        $.alert("${ctp:i18n('common.choose.one.record.label')}");
        return;
  }
  var url = _ctxPath+"/cip/flowEvent/CipFlowEventController.do?method=updateBusiness&type=show&flowId="+v[0].id+"&businessType="+v[0].business_Type;

  //单位管控-单位管理员 添加accountId
  if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"=="true"){
      url = url + "&accountId=" +$("#accountId").val();
  }
  var isOpenState = false;
  if(windowsMap){
      var exitWin = windowsMap.get(v[0].id);
      if(!exitWin){
        var cacthData = businessMap.get(v[0].form_id);
        if(cacthData && cacthData==v[0].id){
          businessMap.remove(v[0].form_id);
        }
      }
  }
  var cacthData = businessMap.get(v[0].form_id);
  if(cacthData && cacthData!=v[0].id){
      $.alert("${ctp:i18n('cip.business.updateOneData')}");
      return;
  }
  businessMap.putRef(v[0].form_id,v[0].id);
  getCtpTop()._businessMap = businessMap;
  openCtpWindow({'url':url,"id":v[0].id});
}

/**
 * 初始化列表组件
 */
function initGrid() {
    var $businessTable = $("#businessTable");
    gridObj = $businessTable.ajaxgrid({
    	gridType:'autoGrid',
        colModel : [ {
            display : 'id',
            name : 'id',
            width : 'smallest',
            sortable : false,
            align : 'center',
            type : 'checkbox',
            isToggleHideShow : false
        }, {
            display : "${ctp:i18n('cip.business.name')}",
            name : 'flow_name',
            width : 'medium'
        }, {
            display : "${ctp:i18n('cip.business.form')}",
            name : 'form_name',
            width : 'medium'
        }, {
            display : "${ctp:i18n('common.template.label')}",
            name : 'workflowName',
            width : 'medium'
        }, {
            display : "${ctp:i18n('cip.business.desc')}",
            name : 'ext_attr4',
            width : 'medium'
        }, {
            display : "${ctp:i18n('cip.business.linkedApp')}",
            name : 'relationApp',
            width : 'medium'
        }, {
            display : "${ctp:i18n('cip.deployment.IntegratedType')}",
            name : 'business_Type',
            width : 'medium',
            codecfg:"codeType:'java',codeId:'com.seeyon.apps.cip.business.enums.BusinessTypeEnum'"
        }],
        //click : updateBusiness,
        dblclick : updateBusiness,
        resizable : false,
        managerName : "cipFlowEventManager",
        managerMethod : "listBusinessVo",
        parentId : $('.layout_center').eq(0).attr('id'),
        height : 360
    });
    var o = {};
    o.flowTypeId = "-1";
    //单位管控-单位管理员 添加accountId
    if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"=="true"){
      o.accountId = $("#accountId").val();
    }
    //集团管控-单位管理员 不加载列表
    if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&!isAccountCtlForBusienss}"!="true"){
      $businessTable.ajaxgridLoad(o);
      /*if(!callBackendMethod("cipDataCheckManager","checkFormDataValid",o)){
          $.alert("${ctp:i18n('cip.business.check.msg1')}");
      }*/
    }

}

/**
 * 用于修改显示列表的应用名称
 */
function rend(txt, data, r, c){
	if(c==5){
	    var appInfoStr = "";
	    var type = "relationApp";
	    //类型是公文
	    if(data.business_Type == 3){
	      appInfoStr = callBackendMethod("cipConfigManager","findCIPConfig",type,data.template_id);
	    }else{
	      appInfoStr = callBackendMethod("cipConfigManager","findCIPConfig",type,data.form_id);
	    }
	    var appInfoObj = eval(appInfoStr);
		var registerIds = [];
		if(appInfoObj){
			for (var i = 0; i < appInfoObj.length; i++) {
				registerIds[i] = appInfoObj[i].registerId;
			}
			var names = callBackendMethod("registerManager","findRegisterNames",registerIds.join(","));
			return names;
		}
		return txt;
	}
	return txt;
}

/**
 * 初始化工具栏组件
 */
function initToolbar() {
	 var businessPluginCat = new Array();
	 var businessPluginApp = new Array();
	 var businessPluginExp = new Array();
	 businessPluginExp.push({id: "import3", name: "${ctp:i18n('common.import.label')}", className: "ico16 import_16", click: importComponent});

	 businessPluginCat.push({id: "createType", name: "${ctp:i18n('cip.base.interface.register.newtype')}", className: "ico16", click: createType});
	 businessPluginApp.push({id: "create", name: "${ctp:i18n('cip.business.label.createBusiness')}", className: "ico16", click: createBusiness});
	 businessPluginExp.push({id: "export3", name: "${ctp:i18n('common.export.label')}", className: "ico16 export_16", click: exportBusiness});

	 businessPluginCat.push({id: "modifyType", name: "${ctp:i18n('cip.base.interface.register.changetype')}", className: "ico16 editor_16", click: updateType});
	 businessPluginCat.push({id: "deleteType", name: "${ctp:i18n('cip.base.interface.register.deltype')}", className: "ico16 del_16", click: deleteType});
	 
	 businessPluginApp.push({id: "modify", name: "${ctp:i18n('cip.business.label.updateBusiness')}", className: "ico16 editor_16", click: updateBusiness});
	 businessPluginApp.push({id: "delete", name: "${ctp:i18n('cip.business.label.deleteBusiness')}", className: "ico16 del_16", click: deleteBusiness});
	 var toolbar = $("#toolbars").toolbar({
        toolbar : [{
            id: "businessType",
            name: "${ctp:i18n('cip.business.label.businesstype')}",
            className: "ico16 text_type_16",
            subMenu:businessPluginCat},
            {
            id: "business",
            name: "${ctp:i18n('cip.business.label')}",
            className: "ico16 modify_text_16 ",
            subMenu:businessPluginApp},
            {
             id: "excel3",
             name: "${ctp:i18n('form.formmasterdatalist.inportexport')}",
             className: "ico16 import_16",
             subMenu:businessPluginExp},
            {
            id:"check",
            name:"${ctp:i18n('cip.business.label.check')}",
            className: "ico16 search_16",
            click: function (){
                checkFormChange();
            }
        }]
    });

    //集团管控-单位管理员按钮全部置灰
    if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&!isAccountCtlForBusienss}"==="true"){
      toolbar.disabledAll();
    }
    //单位管控-集团管理员屏蔽增删改业务集成按钮
    if("${v3x:currentUser().isGroupAdmin()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"==="true"){
      toolbar.hideBtn("business");
    }

    //单位管控-单位管理员显示本单位的相关数据，屏蔽分类增删改按钮
    if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"==="true"){
      toolbar.hideBtn("businessType");
    }

}

function checkFormChange(){
	var dialog = getCtpTop().$.dialog({
        url:"${path}/cip/cipDataCheckController.do?method=check&flowTypeId="+$("#flowTypeId").val()+"&accountId="+$("#accountId").val(),
        width: 680,
        height: 450,
        title: "${ctp:i18n('cip.business.check.changemsg')}",//${ctp:i18n('cip.third.semanic.inter')}
        buttons: [{
            text: "${ctp:i18n('common.button.close.label')}", //关闭
            handler: function () {dialog.close();}
        }]
	});
}
/**
 * 删除业务集成
 */
function deleteBusiness(){
	var hasChecked = $("input:checked", $("#businessTable"));
    if (hasChecked.length == 0) {
        $.alert("${ctp:i18n('cip.base.interface.register.tip30')}");
        return;
    }
    var id = "";
    var pid = "";
    for (var i = 0; i < hasChecked.length; i++) {
      if(id == ""){
            id = hasChecked[i].value;
            pid = hasChecked[i].value;
      }else{
        id += "," + hasChecked[i].value;
      }
    }
	var o = {};
	//选择根节点时,flowTypeId=1,导致后台查询数据空
	var flowTypeId = $("#flowTypeId").val();
	if(flowTypeId == "" || flowTypeId == 1){
		flowTypeId = "-1";
	}
	o.flowTypeId = flowTypeId;
	var eventManager = new cipFlowEventManager();
	$.confirm({
		'msg': "${ctp:i18n('common.isdelete.label')}",
		ok_fn: function() {
			var res = eventManager.deleteCipFlowEvent(id);
			if(res == "success"){
				var $business = $("#businessTable");
				$business.ajaxgridLoad(o);
			}
		}
	});
}
/**
 * 新建业务集成
 */
function createBusiness(){
  if($("#node_type").val() == "-1" || $("#node_type").val() == ""){
    $.alert("${ctp:i18n('cip.business.selectNode')}");
    return;
  }
  var nodeNames = $("#node_name").val();
  var nodeName = nodeNames.substring(nodeNames.lastIndexOf("-")+1,nodeNames.length);
  var nodeId = $("#node_id").val();
  var url = _ctxPath+"/cip/flowEvent/CipFlowEventController.do?method=createBusiness&flowTypeName="+encodeURIComponent(nodeName)+"&flowTypeId="+nodeId;
  //单位管控-单位管理员 添加accountId
  if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"=="true"){
      url = url + "&accountId=" +$("#accountId").val();
  }
  openCtpWindow({'url':url});
}

/**
 * 删除树节点
 */
function deleteType(){
  if($("#node_type").val() == ""){
    $.alert("${ctp:i18n('cip.base.interface.register.tip27')}");
    return;
  }else if ($("#node_type").val() == "-1"){
    $.alert("${ctp:i18n('cip.base.interface.register.tip28')}");
    return;
  }
  if($("#node_children").val() == "1"){
    $.alert("${ctp:i18n('cip.base.interface.register.tip11')}");
    return;
  }
  var isHaveBusiness = callBackendMethod("cipFlowEventManager","isHaveBusiness",$("#node_id").val());
  //单位管控下，集团管理员删除分类提醒调整
  if("${v3x:currentUser().isGroupAdmin()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"==="true" && isHaveBusiness){
      $.alert("${ctp:i18n('cip.business.businesstype.cantDelete')}");
      return;
  }

  var msg = "${ctp:i18n('cip.business.delete.message')}";
  if(!isHaveBusiness){
	  msg = "${ctp:i18n('common.isdelete.label')}";
  }
  $.confirm({
        'msg': msg,
        ok_fn: function() {
          callBackendMethod("cipFlowEventManager","deleteBusinessType",$("#node_id").val(),{
            success:function(returnValue){
                  if(returnValue == "success"){
                    var $businessTree = $("#businessTree");
                    var treeObj = $businessTree.treeObj();
                    var nodes = treeObj.getSelectedNodes();
                    var node = nodes[0];
                    treeObj.removeNode(node);
                    $("#node_type").val("");
                    location.reload();
                  }else{
                    $.alert("${ctp:i18n('cip.base.interface.register.tip22')}");
                  }
            }
          });
        }
    });
}

/**
 * 新建树节点
 */
function createType(){
  showBusinessType();
}
/**
 * 修改树节点
 */
function updateType(){
  if($("#node_type").val() == ""){
    $.alert("${ctp:i18n('cip.base.interface.register.tip24')}");
    return;
  }else if ($("#node_type").val() == "-1"){
    $.alert("${ctp:i18n('cip.base.interface.register.tip25')}");
    return;
  }
  editBusinessType();
}

/**
 * 修改树节点
 */
function editBusinessType(target){
  var nodeId = $("#node_id").val();
  var nodeName = $("#node_name").val();
  if(nodeId == ""){
    $.alert("${ctp:i18n('cip.base.interface.register.tip1')}");
    return;
  }

  var dialog = $.dialog({
           url:"${path}/cip/flowEvent/CipFlowEventController.do?method=editType&id="+encodeURI(nodeId)+"&name="+encodeURI(nodeName),
           width: 450,
           height: 150,
           title: "${ctp:i18n('cip.base.interface.detail.type')}",
           buttons: [{
               text: "${ctp:i18n('common.button.ok.label')}",
               isEmphasize: true,
               handler: function () {
                  var rv = dialog.getReturnValue();
                  if(rv.name != ""){
                    var reg=/^[\u4e00-\u9fa50-9a-zA-Z_]+$/;
                      if(!reg.test(rv.name)){
                        $.alert("${ctp:i18n('cip.base.interface.register.tip14')}");
                        return;
                      }
                      if(rv.name.length > 25){
                        $.alert("${ctp:i18n('cip.base.interface.register.tip21')}");
                        return;
                      }
                      callBackendMethod("cipFlowEventManager","editBusinessType",rv.id, rv.name,
            {success:
              function(returnValue){
                if(returnValue == "success"){
                    $.infor("${ctp:i18n('common.modify.success.label')}");
                            dialog.close();
                            var $businessTree = $("#businessTree");
                          var treeObj = $businessTree.treeObj();
                          var nodes = treeObj.getSelectedNodes();
                          var node = nodes[0];
                          node.data.name = rv.name;
                          node.name = rv.name;
                          var names = $("#node_name").val().split("-");
                            var titleName = "";
                            for(var i = 0; i < names.length - 1; i++){
                              if("" == titleName){
                                titleName = names[i];
                              }else{
                                titleName = titleName + "-" + names[i];
                              }
                            }
                            titleName = titleName + "-" + rv.name;
                          $("#node_name").val(titleName);
                          treeObj.updateNode(node);
                          var o = {};
                          o.treeValue = nodeChildrenIds;
                          var $businessTable = $("#businessTable");
                            $businessTable.ajaxgridLoad(o);
                    }else{
                    $.alert("${ctp:i18n('cip.base.interface.register.tip4')}");
                    }
              }
            }
                      );
                  }else{
                    $.alert("${ctp:i18n('cip.base.interface.register.tip5')}");
                  }
               }
           }, {
               text: "${ctp:i18n('common.button.cancel.label')}",
               handler: function () {
                 dialog.close();
               }
           }]
   });
}

function nodeClk(e, treeId, node) {
  //集团管控-单位管理员 不进行加载数据直接return
  if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&!isAccountCtlForBusienss}"==="true"){
    return;
  }
  $("#rpInputChange").val("20");
  //$("#grid_go").trigger("click");
  if(node.data.type == "1"){
    $("#businessTypeId").val(node.data.id);
  }
  nodeChildrenIds = "";
  if(node.data.type == "-1"){
    nodeChildrenIds = "-1";
  }else if(node.data.type == "1"){
    nodeChildrenIds = getAllChildrenNodes(node, node.id);
  }
  $("#flowTypeId").val(nodeChildrenIds);
  var o = {};
  o.flowTypeId = nodeChildrenIds;
  //单位管控-单位管理员 添加accountId
  if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"=="true"){
    o.accountId = $("#accountId").val();
  }
  var $businessTable = $("#businessTable");
  $businessTable.ajaxgridLoad(o);
  if(node.children == null){
    $("#node_children").val("0");
  }else{
    $("#node_children").val("1");
  }
    $("#node_id").val(node.id);
    var type = "";
    if(node.id == "1"){
      type = "-1";
    }else if(node.getParentNode().id == "1"){
      $("#businessName").val(node.name);
      type = "1";
    }
    var name = node.name;
    var isRoot = 0;
    var arr = new Array();
    if(node.id != "1"){
      var i = 0;
      while(isRoot == 0){
        var pnd = node;
        node = node.getParentNode();
        if(node){
          type = "2";
          arr[i] = node.name;
          i++;
        }else{
        	break;
        }
      }
    }
    var allName = "";
    if(arr.length != 0){
      for(var j = arr.length - 1; j >= 0; j--){
        allName = allName + arr[j] + "-";
      }
    }

    $("#node_type").val(type);
    $("#node_name").val(allName + name);
}

function getAllChildrenNodes(treeNode, result){
    if (treeNode.isParent) {
        var childrenNodes = treeNode.children;
        for (var i = 0; i < childrenNodes.length; i++) {
          if(result != ""){
                result += ',' + childrenNodes[i].id;
          }else{
            result += childrenNodes[i].id;
          }
            result = getAllChildrenNodes(childrenNodes[i], result);
        }
    }
    return result;
}
/**
 * 新建树节点Dialog
 */
function showBusinessType(target){
  var nodeId = $("#node_id").val();
  var nodeName = $("#node_name").val();
  if(nodeId == ""){
    $.alert("${ctp:i18n('cip.base.interface.register.tip1')}");
    return;
  }

  var dialog = $.dialog({
           url:"${path}/cip/flowEvent/CipFlowEventController.do?method=addType&id="+encodeURI(nodeId)+"&name="+encodeURI(nodeName),
           width: 400,
           height: 130,
           title: "${ctp:i18n('cip.business.label.businessType')}",
           buttons: [{
               text: "${ctp:i18n('common.button.ok.label')}",
               isEmphasize: true,
               handler: function () {
                  var rv = dialog.getReturnValue();
                  if(rv.name != ""){
                      var reg=/^[\u4e00-\u9fa50-9a-zA-Z_]+$/;
                      if(!reg.test(rv.name)){
                        $.alert("${ctp:i18n('cip.base.interface.register.tip14')}");
                        return;
                      }
                      if(rv.name.length > 25){
                        $.alert("${ctp:i18n('cip.base.interface.register.tip21')}");
                        return;
                      }
                      callBackendMethod("cipFlowEventManager","addBusinessType",rv.id, rv.name,
            {success:function(returnValue){
                  if(returnValue == "error"){
                    $.alert("${ctp:i18n('cip.base.interface.register.tip4')}");
                  }else{
                  $.infor("${ctp:i18n('cip.base.interface.register.tip3')}");
                          dialog.close();
                          var $businessTree = $("#businessTree");
                          var treeObj = $businessTree.treeObj();
                          var nodes = treeObj.getSelectedNodes();
                          var pnode = nodes[0];
                          var newNode = {"id":returnValue,"pid":pnode.data.id,"name":rv.name,"type":"1"}
                          treeObj.addNodes(pnode, newNode);
                          nodeClk(null, treeObj.setting.treeId, pnode);
                  }
            }
                      });
                  }else{
                    $.alert("${ctp:i18n('cip.base.interface.register.tip5')}");
                  }
               }
           }, {
               text: "${ctp:i18n('common.button.cancel.label')}",
               handler: function () {
                 dialog.close();
               }
           }]
   });
}
/**
 * 初始化搜索框
 */
function initSearchObj() {
    var topSearchSize = 7;
    if ($.browser.msie && $.browser.version == '6.0') {
        topSearchSize = 5;
    }
    var searchObj = $.searchCondition({
        top: topSearchSize,
        right: 10,
        searchHandler: function () {
            var choose = $('#' + searchObj.p.id).find("option:selected").val();
            wholeObj = searchObj;
            var res = searchObj.g.getReturnValue();
      var o = {};
      if(choose == "flowName"){
        o.flowName = res.value;
      }else if(choose == "formName"){
        o.formName = res.value;
      }else if(choose == "workflowName"){//表单流程模版名称
        o.workflowName = res.value;
      }
      o.flowTypeId = nodeChildrenIds;
      //单位管控-单位管理员 添加accountId
      if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&isAccountCtlForBusienss}"=="true"){
        o.accountId = $("#accountId").val();
      }
      //集团管控-单位管理员 查询失效
      if("${v3x:currentUser().isAdministrator()&&v3x:isGroupVer()&&!isAccountCtlForBusienss}"!="true"){
        var $businessTable = $("#businessTable");
        $businessTable.ajaxgridLoad(o);
      }
        },
        conditions: [{
            id: 'flowName',
            name: 'flowName',
            type: 'input',
            text: "${ctp:i18n('cip.business.name')}",
            value: 'flowName'
        },{
          	id: 'formName',
            name: 'formName',
            type: 'input',
            text: "${ctp:i18n('cip.business.form')}",
            value: 'formName'
        },{
          	id: 'workflowName',
            name: 'workflowName',
            type: 'input',
            text: "${ctp:i18n('common.template.label')}",
            value: 'workflowName'
        }]
    });
}
/**
 * 初始化分类树
 */
function initTree() {
    var $businessTree = $("#businessTree");
    $businessTree.tree({
        idKey: "id",
        pIdKey: "parentId",
        nameKey: "name",
        managerName: "cipFlowEventManager",
        managerMethod: "getBusinessTree",
        onClick: nodeClk,
        nodeHandler: function (n) {
            n.open = true;
            if(n.data.type == "1"){
        n.open = false;
      }
        }
    });
    $businessTree.empty();
    $businessTree.treeObj().reAsyncChildNodes(null, "refresh");
}
/**
 * 导入
 */
function importComponent(){
  insertAttachment();
}

function test(isPass,map,attachId,dialog,hasDeeFile){
	//需要知道上传包中的集成类型，然后进行选择表单模版等关联
	if(getCtpTop() && getCtpTop().startProc)getCtpTop().startProc();
	callBackendMethod("cipComponentManager","importCIPComponentForBusiness",attachId,"4",isPass,map,{
		success : function(rv){
            try{if(getCtpTop()&&getCtpTop().endProc){getCtpTop().endProc()}}catch(e){};
			//存在dee的drp文件时，提示优化
            if(hasDeeFile){
            	$.infor("${ctp:i18n('cip.component.interface.import.successForBusiness')}");
            }else{
            	$.infor("${ctp:i18n('cip.component.interface.import.success')}");
            }
			dialog.close();
            var $myTable = $("#businessTable");
            $myTable.ajaxgridLoad();

            //导入成功刷新树
            var $businessTree = $("#businessTree");
            $businessTree.treeObj().reAsyncChildNodes(null, "refresh");
		},error :function(rv){
     		try{if(getCtpTop()&&getCtpTop().endProc){getCtpTop().endProc()}}catch(e){}; 	
			var map = $.parseJSON(rv.responseText);
			if(map){
				$.alert(map.message);
			}
			dialog.close();
		}
	});
}

/**
* 导入回调方法
*/
function importCallBk(attach){
  importComponetCallBack(attach.instance[0],4,showFileData);
}

/**
 * 显示业务集成数据
 * @param  file 
 * @return 
 */
function showFileData(file,attachId){
  var returnMap = callBackendMethod("cipComponentManager","checkSuperNode",attachId);
  if(!returnMap.hasFlowNodeDate){
    $.alert("${ctp:i18n('cip.component.import.oldLevel.label')}");
    return;
  }
  if (returnMap.hasDeeFile && returnMap.noDeeAuth) {
    $.alert("${ctp:i18n('cip.component.import.deeAuth')}");
    return;
  }
  var dialog = $.dialog({
    width: 620,
    height: 400,
    isDrag: false,
    id: 'fileDataDialog',
    url: "${path}/cip/flowEvent/CipFlowEventController.do?method=showFileData&file="+attachId+"&accountId="+$("#accountId").val()+"${ctp:csrfSuffix()}",
    title: "${ctp:i18n('cip.component.import.label')}",
    transParams:returnMap,
    buttons:[{
      text: "${ctp:i18n('common.button.ok.label')}",
      isEmphasize: true,
      handler: function () {
        var rv = dialog.getReturnValue();

        if(rv){
          var random = $.messageBox({
            'type': 100,
            'msg': '${ctp:i18n("cip.component.application.import.confirm")}',
            buttons: [{
              id:'btn1',
              text: "${ctp:i18n('cip.interface.semantic.param.cover')}",//覆盖
              handler: function () {
                test(true,rv,attachId,dialog,returnMap.hasDeeFile);
              }
            }, {
              id:'btn2',
              text: "${ctp:i18n('common.skip.label')}",//跳过
              handler: function () {
                test(false,rv,attachId,dialog,returnMap.hasDeeFile);
              }
            }]
          });
        }
        //dialog.close();
      },
    },{
      text: "${ctp:i18n('common.button.cancel.label')}",
      handler: function () {
        dialog.close();
      }
    }]
  });
}

/**
 * 导出具体实现
 */
function exportBusiness(){
	var v = $("#businessTable").formobj({
		gridFilter : function(data, row) {
			return $("input:checkbox", row)[0].checked;
		}
	});
	var hasEdoc = false;
  if (v.length < 1) {
    $.alert("${ctp:i18n('cip.business.export.message')}");
    return;
  }
  var exportCount = $("#exportCount").val();
  if (v.length > exportCount) {
	  $.alert("${ctp:i18n_1('cip.business.export.exportCount','"+exportCount+"')}");
    return;
  }
  var mainType = v[0].business_Type;
  var hasOtherType = false;
	var flowIds = new Array();
	var flowNames = new Array();
	for(var i=0; i<v.length; i++){
		if(v[i].business_Type == 3){
      hasEdoc = true;
      break;
		}
    if(v[i].business_Type != mainType){
			hasOtherType = true;
      break;
		}else{
      flowIds[i] = v[i].id;
      flowNames[i] = v[i].value0 +"_"+v[i].flow_name;
    }
	}
  if(hasEdoc){
	$.alert("${ctp:i18n('cip.business.export.hasEdoc')}");
	return;
  }

  if (hasOtherType) {
	$.alert("${ctp:i18n('cip.business.export.onlySomeType')}");
    return;
  }

  var dialog = getCtpTop().$.dialog({
    url:"${path}/cip/cipComponentController.do?method=export&type=4&id="+flowIds.join(",")+"&name="+encodeURIComponent(flowNames.join(",")),
    width: 550,
    height: 300,
    title: "${ctp:i18n('cip.base.export')}",//
    buttons: [{
      text: "${ctp:i18n('common.export.label')}", //确定
      isEmphasize: true,
      handler: function () {
        var rv = dialog.getReturnValue();
        if(rv!=false){
        	callBackendMethod("cipComponentManager","checkCompAuthType",rv.sourceId,rv.authType,rv.type,rv.content,{
				success : function(data){
					$("#downLoad").fillform(rv);
					$("#downLoad").submit();
					dialog.close();
				}
			});
        }
      }
    }, {
      text: "${ctp:i18n('common.button.close.label')}", //取消
      handler: function () {
        dialog.close();
      }
    }]
  });
}
</script>
  <div id='layout' class="comp" comp="type:'layout'">
    <div class="layout_north" layout="height:40,sprit:false,border:false">
      <div id="toolbars"></div>
    </div>
    <div class="layout_west" layout="width:200,minWidth:50,maxWidth:300">
      <div id="businessTree"></div>
    </div>
    <div class="layout_center over_hidden" layout="border:false">
      <div id="center">
        <table class="flexme3" id="businessTable"></table>
      </div>
    </div>

      <input type="hidden" id="accountId" value="${ctp:toHTML(param.accountId)}"/>
      <input type="hidden" id="node_id" />
      <input type="hidden" id="node_name" />
      <input type="hidden" id="node_type" />
      <input type="hidden" id="node_children" />
      <input type="hidden" id="businessName" />
      <input type="hidden" id="businessTypeId" />
      <input type="hidden" id="flowTypeId" />
      <input type="hidden" id="flowId" value="${ctp:toHTML(flowId)}">
      <input type="hidden" id="exportCount" value="${ctp:toHTML(exportCount)}">
  </div>
  <div class="comp" style="display: none;" comp="type:'fileupload',applicationCategory:'1',canDeleteOriginalAtts:false,originalAttsNeedClone:false,quantity:1,extensions:'zip,icm',maxSize:1024*1024*10,callMethod:'importCallBk',takeOver:false,firstSave:true">
  </div>
    <form hidden="hidden" id="downLoad" action="${path}/cip/cipComponentController.do?method=downLoad"  method="post">
      <input type="hidden" id="type" name="type" value="">
      <input type="hidden" id="name" name="name" value="">
      <input type="hidden" id="sourceId" name="sourceId" value="">
      <input type="hidden" id="description" name="description" value="">
      <input type="hidden" id="content" name="content" value="">
      <input type="hidden" id="guid" name="guid" value="">
      <input type="hidden" id="authType" name="authType" value="">
      <input type="hidden" id="copyright" name="copyright" value="">
      <input type="hidden" id="extAttr2" name="extAttr2" value="">
    </form>
</body>
</html>
